// 输入对话框 对应jq版本inputdialog_layer
// 入参为title（弹窗标题），label（对话框标签，对话框标题）
<template>
  <el-dialog width="500px" :title="params.title" :visible.sync="params.visible">
    <el-form ref="form" label-width="80px">
      <el-form-item label="名称：" label-width="110px">
        <el-input v-model="formData.name" />
      </el-form-item>
      <el-form-item
        v-if="params.title === '新建流程'"
        label="人工耗时(分钟)："
        label-width="110px"
      >
        <el-input v-model="formData.workTime" />
      </el-form-item>
    </el-form>
    <dialog-btn slot="footer" />
  </el-dialog>
</template>
<script>
export default {
  name: 'InputdialogLayer',
  props: {
    params: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      //   表格数据
      formData: {
        name: '',
        workTime: ''
      }
    }
  },
  create() {},
  methods: {
    isNumber(val) {
      var regPos = /^\d+(\.\d+)?$/ // 非负浮点数
      var regNeg =
        /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/ // 负浮点数
      if (regPos.test(val) || regNeg.test(val)) {
        return true
      } else {
        return false
      }
    },
    confirm() {
      if (this.formData.name === '') {
        return this.$message({
          type: 'warning',
          message: this.label + '不能为空,请输入'
        })
      }
      if (this.formData.workTime !== '') {
        if (this.isNumber(this.formData.workTime)) {
          if (this.formData.workTime < 0) {
            return this.$message({
              type: 'warning',
              message: '人工耗时不能小于0'
            })
          }
        } else {
          return this.$message({
            type: 'warning',
            message: '人工耗时格式不正确'
          })
        }
      }
      this.params.confirm({
        workTime: this.formData.workTime,
        name: this.formData.name
      })
    }
  }
}
</script>
